use std::sync::Arc;

use axum::{middleware, routing::get, Router};
use tokio::net::TcpListener;

mod handler;
mod mw;
mod state;

#[tokio::main]
async fn main() {
    let state = Arc::new(state::AppState::new());

    let app = Router::new()
        .route("/", get(handler::index))
        .layer(middleware::from_fn_with_state(
            state.clone(),
            mw::middleware,
        ))
        .with_state(state);

    let listner = TcpListener::bind(&"127.0.0.1:56789").await.unwrap();

    axum::serve(listner, app.into_make_service()).await.unwrap();
}
